﻿using System;
using System.Data;
using System.Collections.Generic;
using OnlineManagement.Common;
using OnlineManagement.Model;
using OnlineManagement.DALFactory;
using OnlineManagement.IDAL;
namespace OnlineManagement.BLL.Dal
{
	/// <summary>
	/// PigPen
	/// </summary>
	public partial class PigPen
	{
		private readonly IPigPen dal=DataAccess.CreatePigPen();
		public PigPen()
		{}
		#region  BasicMethod
		/// <summary>
		/// 是否存在该记录
		/// </summary>
        public bool Exists(int customerId, int hoggerId)
		{
            return dal.Exists(customerId,hoggerId);
		}
        
		/// <summary>
		/// 增加一条数据
		/// </summary>
        public bool Add(OnlineManagement.Model.PigPen model, string feederName, out string returnValue)
		{
			return dal.Add(model,feederName,out returnValue);
		}
       

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(OnlineManagement.Model.PigPen model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
        public bool Delete(Guid pigPenID, out string message)
		{
            return dal.Delete(pigPenID, out message); 
		}

        public System.Collections.Generic.List<Model.PigPen> GetAllPigPens(int hoggeryId) {
            return dal.GetAllPigPens(hoggeryId);
        }

		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<OnlineManagement.Model.PigPen> DataTableToList(DataTable dt)
		{
			List<OnlineManagement.Model.PigPen> modelList = new List<OnlineManagement.Model.PigPen>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				OnlineManagement.Model.PigPen model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		
		#endregion  BasicMethod

        #region  ExtensionMethod

        /// <summary>
        /// 获取可用的猪舍号
        /// </summary>
        /// <param name="hoggeryId"></param>
        /// <returns></returns>
        public DataSet GetAvailabltePigPens(int hoggeryId)
        {
            return dal.GetAvailabltePigPens(hoggeryId);
        }

        /// <summary>
        /// pigpens paging
        /// </summary>
        /// <param name="hoggeryId"></param>
        /// <param name="strWhere"></param>
        /// <param name="strOrderBy"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="iscount"></param>
        /// <param name="rCount"></param>
        /// <returns></returns>
        public DataSet PigPensByPaging(
            int hoggeryId, string strWhere, string strOrderBy,
            int currentPage, int pageSize, out int rCount)
        {
            return dal.PigPensByPaging(hoggeryId, strWhere, strOrderBy, currentPage, pageSize, out rCount); 
        }

       
        #endregion  ExtensionMethod
	}
}

